package cn.mldn.homework.collect;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;

public class Util
{
	private ArrayList<Student> studentList = new ArrayList<>();
	private ArrayList<Score> mathScoreList = new ArrayList<>();
	private ArrayList<Score> javaScoreList = new ArrayList<>();
	private ArrayList<Score> softwareScoreList = new ArrayList<>();
	
	public Util()
	{
		
	}
	
	public ArrayList<Student> initStudent()
	{
		ArrayList<Student> studentList = new ArrayList<>();
		
		studentList.add( new Student("021", "郭杰瑞"));
		studentList.add( new Student("034", "周铭"));
		studentList.add( new Student("025", "关侍"));
		studentList.add( new Student("009", "刘国伟"));
		studentList.add( new Student("038", "罗致"));
		studentList.add( new Student("059", "吴一凡"));
		studentList.add( new Student("045", "郭魏"));
		
		return studentList;
	}
	
	public ArrayList<Score> initScore(String courseName)
	{	
		ArrayList<Score> scoreList = new ArrayList<>();
	      
	    Random random = new Random();
		final int START = 50;   //定义范围开始数字
	    final int END = 100; //定义范围结束数字
	         
		scoreList.add( new Score("021", courseName,random.nextInt(END - START + 1) + START));
		scoreList.add( new Score("034", courseName,random.nextInt(END - START + 1) + START));
		scoreList.add( new Score("025", courseName,random.nextInt(END - START + 1) + START));
		scoreList.add( new Score("009", courseName,random.nextInt(END - START + 1) + START));
		scoreList.add( new Score("038", courseName,random.nextInt(END - START + 1) + START));
		scoreList.add( new Score("059", courseName,random.nextInt(END - START + 1) + START));
		scoreList.add( new Score("045", courseName,random.nextInt(END - START + 1) + START));
		
		return scoreList;
	}
	
	public double computeAverageScore(ArrayList<Score> scoreList)
	{
		double sum=0;
		
		Iterator<Score> iter = scoreList.iterator();
		while(iter.hasNext())
		{
			Score score = iter.next();
			sum+=score.getScore();
		}
		
		return sum/scoreList.size();
	}
	
	public int computeMaxScore(ArrayList<Score> scoreList)
	{
		int max=0;
		
		Iterator<Score> iter = scoreList.iterator();
		while(iter.hasNext())
		{
			Score score = iter.next();
			if(score.getScore()>max)
			{
				max=score.getScore();
			}
		}
		
		return max;
	}
	
	public int computeMinScore(ArrayList<Score> scoreList)
	{
		int min=101;
		
		Iterator<Score> iter = scoreList.iterator();
		while(iter.hasNext())
		{
			Score score = iter.next();
			if(score.getScore()<min)
			{
				min=score.getScore();
			}
		}
		
		return min;
	}
	
	public void listStudentScore(String id,ArrayList<Score> mathScoreList,ArrayList<Score> javaScoreList,ArrayList<Score> softwareScoreList)
	{
		String infor="学号为"+id+"的学生各科成绩为：";
		
		Iterator<Score> iter = mathScoreList.iterator();
		while(iter.hasNext())
		{
			Score score = iter.next();
			if(score.getId().equals(id))
			{
				infor+="高数"+score.getScore();
			}
		}
		
		Iterator<Score> iter2 = javaScoreList.iterator();
		while(iter2.hasNext())
		{
			Score score = iter2.next();
			if(score.getId().equals(id))
			{
				infor+="  java程序设计"+score.getScore();
			}
		}
		
		Iterator<Score> iter3 = softwareScoreList.iterator();
		while(iter3.hasNext())
		{
			Score score = iter3.next();
			if(score.getId().equals(id))
			{
				infor+="  软件工程"+score.getScore();
			}
		}
		
		System.out.println(infor);
	}
}
